//
//  JXMessageCell.swift
//  Home_School_Luzhu
//
//  Created by 大鼻子露珠 on 2016/12/29.
//  Copyright © 2016年 大鼻子露珠. All rights reserved.
//

import UIKit

class JXMessageCell: UITableViewCell {

    //回复视图约束高度
    @IBOutlet weak var messageReplayViewConst: NSLayoutConstraint!
    
    @IBOutlet weak var messageIconV: UIImageView!//头像
    @IBOutlet weak var messageNameL: UILabel!//姓名
    @IBOutlet weak var messageUserStyle: UILabel!//用户类型
    @IBOutlet weak var messageDateL: UILabel!//
    @IBOutlet weak var messageTitleL: UILabel!
    @IBOutlet weak var messageContentL: UILabel!
    @IBOutlet weak var messageLikeBtn: UIButton!
    @IBOutlet weak var MessageReplayView: FSCReplayVListView!
    
    //点赞按钮回调闭包属性
    var likeBtnBlock:( (_ cell:JXMessageCell)->( ) )?
    var replayBtnBlock: ( (_ cell:JXMessageCell) -> () )?
    
    
    //接收消息模型的数据
    var messageVM:FSCMessageViewModel?{
        
        didSet{
            if let path = messageVM?.message.not_tpath, path != "" {
                let urlStr = "http://120.24.57.38/new/zao/" + path
                //使用AFN下载图片
                messageIconV.setImageWith(URL(string: urlStr)!)
            }else {
                if messageVM?.message.not_sex == "女" {
                    messageIconV.image = UIImage(named: "girl")
                }else {
                    messageIconV.image = UIImage(named: "boy")
                }
            }
            
            messageNameL.text = messageVM?.message.not_Name
            messageDateL.text = messageVM?.message.not_createDate
            messageTitleL.text = messageVM?.message.not_title
            messageContentL.text = messageVM?.message.not_content
            //设置点赞数和显示高亮状态下的点赞图片
            if (messageVM?.message.likenum)! > 0 {
                messageLikeBtn.isSelected = true
                messageLikeBtn.setTitle("\(messageVM?.message.likenum ?? 0)", for: .selected)
            } else {
                messageLikeBtn.isSelected = false
            }
            //传递数据给回复列表
            MessageReplayView.messageVM = messageVM
            
            //更新视图模型设置高度
            messageReplayViewConst.constant = messageVM?.replayListViewH ?? 0
        }
    }
    
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        //设置视图
        messageIconV.layer.cornerRadius = 25
        messageIconV.layer.masksToBounds = true
        messageUserStyle.layer.cornerRadius = 8
        
        messageUserStyle.layer.borderWidth = 1
        messageUserStyle.layer.borderColor = UIColor.colorWithHex(hexColor: 0x00a0e9).cgColor
        
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    
//MARK:按钮事件

    @IBAction func replayBtnClicked(_ sender: UIButton) {
        replayBtnBlock?(self)

    }
    
    @IBAction func likeBtnClicked(_ sender: UIButton) {
        likeBtnBlock?(self)

    }
  
}
